package cn.lyh.service.impl;

import cn.lyh.domain.Order;
import cn.lyh.mapper.OrderMapper;
import cn.lyh.service.AccountService;
import cn.lyh.service.IOrderService;
import cn.lyh.service.StorageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liangYiHui
 * @since 2021-07-19
 */
@Service
@Slf4j
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {
    @Resource
    private OrderMapper orderMapper;
    @Resource
    private StorageService storageService;
    @Resource
    private AccountService accountService;

    public void create(Order order){
        log.info("----------------->开始创建订单");
        this.save(order);

        log.info("----------------->开始减库存-count");
        storageService.decrease(order.getProductId(),order.getCount());
        log.info("----------------->开始减库存-count-end");

        log.info("----------------->开始减存钱-money");
        accountService.decrease(order.getUserId(),order.getMoney());
        log.info("----------------->开始减存钱-money-end");

        log.info("----------------->修改用户状态");
        order.setStatus(1);
        orderMapper.updateById(order);
        log.info("----------------->修改用户状态end");

    }

}
